package com.zj.blessings.util;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
import cn.sharesdk.onekeyshare.OnekeyShare;

import com.zj.blessings.OneKeyShareCallback;
import com.zj.blessings.R;
import com.zj.blessings.db.DBItem;
import com.zj.blessings.db.DBLikeItem;
import com.zj.blessings.form.RemoteItem;

public class ShareUtils {
	public static void showShare(Context context, String platform,
			Boolean silent, Object object) {
		String title = "";
		String text = "";
		if (object instanceof DBItem) {
			title = ((DBItem) object).title;
			text = ((DBItem) object).text;
		} else if (object instanceof DBLikeItem) {
			title = ((DBLikeItem) object).title;
			text = ((DBLikeItem) object).text;
		} else if (object instanceof RemoteItem) {
			title = ((RemoteItem) object).getTitle();
			text = ((RemoteItem) object).getContent();
		}
		// final OnekeyShare oks = new OnekeyShare();
		// oks.setNotification(R.drawable.ic_launcher,
		// context.getString(R.string.app_name));
		// oks.setTitle(title);
		// oks.setText(text);
		// // oks.setComment("这款软件真的很不错！");
		// // oks.setSiteUrl("http://sharesdk.cn");
		// // oks.setVenueName("Share SDK");
		// // oks.setTitleUrl("http://www.baidu.com");
		// //
		// oks.setImageUrl("http://img.appgo.cn/imgs/sharesdk/content/2013/07/25/1374723172663.jpg");
		// oks.setSilent(silent);
		// // oks.setVenueName("搞笑吧");
		// if (platform != null) {
		// oks.setPlatform(platform);
		// }
		// // 去除注释，则快捷分享的操作结果将通过OneKeyShareCallback回调
		// oks.setCallback(new OneKeyShareCallback());
		// // 去除注释，演示在九宫格设置自定义的图标
		// oks.show(context);
		String path = FileUtils.getFilePath();
		final OnekeyShare oks = new OnekeyShare();
		oks.setNotification(R.drawable.ic_launcher,
				context.getString(R.string.app_name));
		oks.setAddress(null);
		oks.setTitle(title);
		oks.setTitleUrl("http://www.mumayi.com/android-220289.html");
		oks.setText(text);
		oks.setImagePath(path);
		oks.setImageUrl("http://tp4.sinaimg.cn/2112364483/180/5667476463/1");
		oks.setUrl("http://www.baidu.com");
		oks.setFilePath(path);
		oks.setComment("这款应用真的很不错，推荐大家使用！");
		oks.setSite(context.getString(R.string.app_name));
		oks.setSiteUrl("http://www.mumayi.com/android-220289.html");
		oks.setVenueName("笑屎啦");
		oks.setVenueDescription("这款应用真的很不错，推荐大家使用！");
		oks.setLatitude(23.056081f);
		oks.setLongitude(113.385708f);
		oks.setSilent(silent);
		if (platform != null) {
			oks.setPlatform(platform);
		}

		// 去除注释，可令编辑页面显示为Dialog模式
		// oks.setDialogMode();

		// 去除注释，在自动授权时可以禁用SSO方式
		// oks.disableSSOWhenAuthorize();

		// 去除注释，则快捷分享的操作结果将通过OneKeyShareCallback回调
		oks.setCallback(new OneKeyShareCallback(new ShareUtils.ShareHandler(
				context)));
		// oks.setShareContentCustomizeCallback(new
		// ShareContentCustomizeDemo());

		// 去除注释，演示在九宫格设置自定义的图标
		// Bitmap logo = BitmapFactory.decodeResource(menu.getResources(),
		// R.drawable.ic_launcher);
		// String label = menu.getResources().getString(R.string.app_name);
		// OnClickListener listener = new OnClickListener() {
		// public void onClick(View v) {
		// String text = "Customer Logo -- ShareSDK " +
		// ShareSDK.getSDKVersionName();
		// Toast.makeText(menu.getContext(), text, Toast.LENGTH_SHORT).show();
		// oks.finish();
		// }
		// };
		// oks.setCustomerLogo(logo, label, listener);

		oks.show(context);
	}

	static class ShareHandler extends Handler {
		private Context mContext;

		public ShareHandler(Context context) {
			this.mContext = context;
		}

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case OneKeyShareCallback.SUCCEED:
				Toast.makeText(mContext, "分享成功", Toast.LENGTH_SHORT).show();
				break;
			case OneKeyShareCallback.ERROR:
				Toast.makeText(mContext, "分享失败", Toast.LENGTH_SHORT).show();
				break;
			case OneKeyShareCallback.CANCEL:
				Toast.makeText(mContext, "取消分享", Toast.LENGTH_SHORT).show();
				break;
			}
		}
	}
}
